<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="search"/>
        <ul>
            <li v-for="item in finallyPersons" :key="item.id">
                姓名：{{item.name}}--年龄：{{item.age}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false

        const vm = new Vue({
            el:'#app',
            data(){
                return{
                    search:'',

                    persons:[
                        { id: "001", name: "周杰伦", age: 19 },
                        { id: "002", name: "陈奕迅", age: 25 },
                        { id: "003", name: "周杰", age: 39 },
                        { id: "004", name: "陈冠希", age: 7 },
                        { id: "005", name: "谢坤", age: 22 },
                        { id: "006", name: "杨坤", age: 14 },
                        { id: "007", name: "谢霆锋", age: 11 },
                    ],
                    finallyPersons:[],
                }
            },
            watch:{
                search: {
                    immediate: true,
                    handler(){
                        this.finallyPersons = this.persons.filter((item)=>{
                            return item.name.includes(this.search)
                        })
                    }
                }
            }
        })

        vm.unWatch = vm.$watch(
            'count',
            function(){
                console.log('count改变了')
                console.log(this)
            },
            {
                deep: true,
                immediate: true
            }
        )
    </script>

</body>
</html>